/* 
    [["a", "b"], ["n", "m"], ["0", "1"]] 转为 ["am0", "am1", "an0", "an1", "bm0", "bm1", "bn0", "bn1"]
*/

const matrix = [
  ["a", "b"],
  ["m", "n"],
  ["0", "1"],
];

/* 常规写法 */
{
  const fn = (arr) => {
    let result = arr[0];

    const generate = (temp) => {
      const a = [];
      for (let i = 0; i < result.length; i++) {
        for (let j = 0; j < temp.length; j++) {
          a.push(result[i] + temp[j]);
        }
      }
      return a;
    };

    for (let i = 1; i < arr.length; i++) {
      result = generate(arr[i]);
      if (i === arr.length - 1) {
        return result;
      }
    }
  };
  console.log(fn(matrix));
}
